try:
   import netCDF4 as nc
except:
   import netCDF3 as nc

def pyinqfile(fin):
   '''
     fin : input netcdf file
     
     writes basic information about netcdffile
   '''
   fid=nc.Dataset(fin,'r','NETCDF3_CLASSIC')
   print 'dimensions in file ' + fin + ' :'
   i=0
   for dim in fid.dimensions.values():
       print dim
   
   print fin + ' format is ' + fid.file_format
   
   print 'variables in files :'
   for var in fid.variables.items():
       print var
   fid.close()   
   
def pyinqvar(fin,var=None):
    '''
      fin: Input netcdf file
      var: variable for which information is saught
      
      if no variable name is given, all variables info is printed
    '''
    fid=nc.Dataset(fin,'r','NETCDF3_CLASSIC')
    nvar=fid.variables.keys()

    i=0
    PrintSuccess=0
    for val in fid.variables.values():
        if var is None:
           print val
           PrintSuccess=1
        elif i == nvar.index(var):
           print val
           PrintSuccess=1
        i+=1
           
    if not PrintSuccess:
       print 'variable not found !!!'
    fid.close() 
      

